import React, { Component } from 'react';
import { ContContext } from '../context/contContext';

class ContextApp extends Component {
    constructor(props) {
        super(props);
        this.state = {
            obj: {
                name: '门将',
                age: '12',
                describe: '这是一位好老师'
            }
        };
        this.infChange = this.infChange.bind(this);
    }

    infChange(newObj) {
        const { obj } = this.state;
        const resObj = { ...obj, ...newObj };
        this.setState({ obj: resObj });
    }

    render() {
        const { obj } = this.state;
        const { children } = this.props;
        return <ContContext.Provider value={{ obj, infChange: this.infChange }}>{children}</ContContext.Provider>;
    }
}
export default ContextApp;
